<template>
  <div id="app">
    <router-view ref="app" />
  </div>
</template>

<script>
import { toFix } from '@/utils/validate.js'
export default {
  name: 'App',
  provide() {
    return {
      app: this
    }
  },
  data() {
    return {
      loading: false
    }
  },
  methods: {
    appMain() {
      const len = this.$refs['app'].$children.length || 0
      for (let i = 0; i < len; i++) {
        const children = this.$refs['app'].$children[i]
        if (children.$refs['app-main']) {
          return children.$refs['app-main']
        }
      }
      return null
    },
    toFix(v, n) {
      return toFix(v, n)
    },
    removeLoding() {
      setTimeout(() => {
        this.loading = false
      }, 500)
    },
    dialogParam(obj, arr, row) {
      arr.forEach(item => {
        this.$set(obj, item, row && (row[item] || row[item] === 0) ? row[item] : '')
      })
    },
    resetFields(main, e) {
      this.$nextTick(() => {
        if (main && main.$refs[e]) {
          const data = {}
          data['pageNumber'] = main[e]['pageNumber']
          data['pageCurrent'] = main[e]['pageCurrent']
          data['pageAll'] = main[e]['pageAll']
          main[e] = data
          main.$refs[e].resetFields()
        }
      })
    },
    reset(e) {
      this.$nextTick(() => {
        const main = this.appMain()
        if (main && main.$refs[e]) {
          const data = {}
          data['pageNumber'] = main[e]['pageNumber']
          data['pageCurrent'] = main[e]['pageCurrent']
          data['pageAll'] = main[e]['pageAll']
          main[e] = data
          main.$refs[e].resetFields()
        }
      })
    }
  }
}
</script>
